import java.io.IOException;
import java.io.PrintWriter;
import java.net.*;

public class GameBoard implements Runnable{

	final int numOfSquares = 30;
	
	Game currGame;
	Game[] games = new Game[numOfSquares];
	Player[] players;
	PrintWriter out;
	
	// Threadz
	Thread animation; // This thread is used for animation (aka graffix, aka not my problem)
	Thread game; // This thread is used for playing the game
	Thread main; // This thread is used for just simply updating of the screen
	Thread currentThread;
	
	public GameBoard(int numberOfPlayers, Player p, Socket s) {
		players = new Player[numberOfPlayers];
		addGames(getGames());
		try {
		out = new PrintWriter(s.getOutputStream(), true);
		}catch(IOException e) {}
	}
	
	
	// This method chooses and adds Games to the games array.
	// The method of choosing is currently undecided. Although
	// when we add a Game to the games array make sure to set
	// which point it's at (so we know where to draw the player)
	public void addGames(Game[] g) {
		/* code goes here */
	}
	
	// This method loads the games we could play, we take this
	// array and put into a method which chooses which games
	// to play (see addGames)
	public Game[] loadGames() { 
		/* code goes here */
		return null;
	}
	
	public void run() {
		try {
			if(currentThread == animation) {
				// This is for player movements on the GameBoard
				System.out.println("draw stuff");
				currentThread = main; 
			}
			if(currentThread == game) {
				currGame.play();
				currentThread.sleep(1000);
			}
			if(currentThread == main) {
				disp();
			}
			currentThread.sleep(100);
		} catch(InterruptedException e) {}
	}
	
	public void setState(char s) {
		if(s == ' ')
			return;
		if(s == 'g')
			currentThread = game;
		if(s == 'a')
			currentThread = animation;
		if(s == 'e')
			currentThread = main;
	}
	
	public void setGame(Game g, boolean original) {
		currGame = g;
		if(original)
			out.print("GAME" + g.getID());
	}

	public Game[] getGames() {
		return games;
	}
	
	public void disp() {
		
	}
	
	
	
	public void movePiece(int dist, boolean original) {
		if(original)
			out.write("REFRESH");
		// a pretty animation goes here, the idea is that we can 
		// tell the other computers to do the animation (with using
		// original to make sure the program doesn't explode)
	}
	
	
} 